package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.CmsConfigCriteria;
import com.lin.cms.domain.CmsConfig;
import com.lin.cms.service.CmsConfigService;
import com.lin.cms.dao.CmsConfigMapper;

@Service
public class CmsConfigServiceImpl implements CmsConfigService{
	
	public CmsConfig selectByPrimaryKey(Integer configId){
		return cmsConfigMapper.selectByPrimaryKey(configId);
	}
	
	public List<CmsConfig> selectByCriteria(CmsConfigCriteria criteria){
		return cmsConfigMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer configId){
		int actualRowsAffected = 0;
		
		CmsConfig _oldCmsConfig = cmsConfigMapper.selectByPrimaryKey(configId);
		
		if (_oldCmsConfig != null) {
			actualRowsAffected = cmsConfigMapper.deleteByPrimaryKey(configId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(CmsConfigCriteria criteria){
		int actualRowsAffected = 0;
		
		List<CmsConfig> _oldCmsConfig = cmsConfigMapper.selectByCriteria(criteria);
		
		if (_oldCmsConfig.size() != 0) {
			actualRowsAffected = cmsConfigMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(CmsConfig cmsConfig){
		return cmsConfigMapper.insert(cmsConfig);
	}
	
	public int updateByPrimaryKeySelective(CmsConfig cmsConfig){
		int actualRowsAffected = 0;
		
		int advertisingId = cmsConfig.getConfigId();

		CmsConfig _oldCmsConfig = cmsConfigMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldCmsConfig != null) {
			actualRowsAffected = cmsConfigMapper.updateByPrimaryKeySelective(cmsConfig);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(CmsConfig cmsConfig){
		int actualRowsAffected = 0;
		
		int advertisingId = cmsConfig.getConfigId();

		CmsConfig _oldCmsConfig = cmsConfigMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldCmsConfig != null) {
			actualRowsAffected = cmsConfigMapper.updateByPrimaryKey(cmsConfig);
		}
		
		return actualRowsAffected;
	}
	
	public List<CmsConfig> selectByPage(CmsConfigCriteria criteria) {
		int totalResults = cmsConfigMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return cmsConfigMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(CmsConfigCriteria criteria){
		return cmsConfigMapper.countByCriteria(criteria);
	}
	
	@Autowired
    private CmsConfigMapper cmsConfigMapper;
}
